<?php
 include "counter.php";

  if (!$region) {
    $region = 'All';
  }
  if ($region == 'All') {
    $total = dbcount("machines");
  } else {
    $total = dbcount("machines", "country='$region'");
  }

?>
<?php pagehead("Distribution used by region") ?>
<BODY bgcolor="white">
<?php pagetop() ?>
<h1>Linux distributions used in <?php echo $region ?></h1>
Out of a total of <?php echo $total ?> machines registered:

<table border>
<?php

if ($region == 'All') {
$query = mysql_query("select count(*) as c, distribution from machines
       group by distribution order by c
       desc");
} else {
$query = mysql_query("select count(*) as c, distribution from machines
       where country = '$region' group by distribution order by c
       desc");
}
if (!$query) {
     print('MySQL error: '. mysql_errno() .':'. mysql_error());
      die('Query for count failed');
}


while ($arr = mysql_fetch_array($query)) {
   printf("<tr><td>%5d<td>%5.1f%%<td>%s\n",
        $arr["c"], $arr["c"] * 100 / $total,
	"<a href=\"regionbydist.php?distribution="
	. urlencode($arr["distribution"]) . "\">" .
        $arr["distribution"] . "</a>");
}
?>
</table>



<?php pagebottom() ?>
</body>
</html>


